<?php
	class Upload {
		//文件保存(一张的)浏览框的名字为pic
		function savePic($path){
			//是否成功
			if($_FILES['pic']['error'] == 0){
				//判断类型
				$type=strtolower($_FILES['pic']['type']);
				if($type == "image/jpeg" || $type == "image/png" ||$type == "image/jpg"||$type == "image/bmp"||$type == "image/gif"){				
					//大小
					if($_FILES['pic']['size'] <=20000000 ){
						//转移
						$nameArr = explode(".",$_FILES['pic']['name']);
						$extName = end($nameArr);
						$fileName = time().mt_rand(100,999).".".$extName;
						move_uploaded_file($_FILES['pic']['tmp_name'], $path."/".$fileName);
						return $path."/".$fileName;
					}else{
						return false;
					}
				}else{
					return false;
				}
			}else{
				return false;
			}
		}
		//文件保(存多张的) pic[1]名字为数组从1开始
		function savePicMore($path){
		    $reArr = array();//保存每次上传成功后的图片路径
		    $errorArr = $_FILES['pic']['error'];
			foreach ($errorArr as $k=>$v){
				
			    //是否成功
			    if($v == 0){
			        //判断类型
			        $type=strtolower($_FILES['pic']['type'][$k]);
			        if($type == "image/jpeg" || $type == "image/png" ||$type == "image/jpg" ||$type == "image/gif" ||$type == "image/bmp"){
			            //大小
			            if($_FILES['pic']['size'][$k] <=2000000 ){
			                //转移
			                $nameArr = explode(".",$_FILES['pic']['name'][$k]);
			                $extName = end($nameArr);
			                $fileName = time().mt_rand(100,999).".".$extName;
			                move_uploaded_file($_FILES['pic']['tmp_name'][$k], $path."/".$fileName);
							$reArr["pic".$k] = $path."/".$fileName;
			            }else{
			                $reArr["pic".$k]="";
			            }
			        }else{
			          $reArr["pic".$k]="";
			        }
			    }else{
			        $reArr["pic".$k]="";
			    }
			}
			return $reArr;
		    
		}
		
		
	}
?>